package com.springboot.original.controller;

import com.springboot.original.domain.StudentAnswerQuestionRecord;
import com.springboot.original.domain.StudentAnswerQuestionRecordKey;
import com.springboot.original.service.UserService;

import java.util.concurrent.Callable;

/**
 *
 * @author zhangliang
 */
public class PushTaskItemTread implements Callable<StudentAnswerQuestionRecordKey> {

    private StudentAnswerQuestionRecordKey answerQuestionRecordKey;

    private UserService userService;

    private int count;

    public PushTaskItemTread(StudentAnswerQuestionRecordKey answerQuestionRecordKey,UserService userService,int count) {
        this.answerQuestionRecordKey = answerQuestionRecordKey;
        this.userService = userService;
        this.count = count;
    }

    @Override
    public StudentAnswerQuestionRecordKey call() {

        Thread th=Thread.currentThread();
        System.out.println("当前线程 Tread name:"+th.getName()+ "正在执行处理第 "+count+" 条： "+answerQuestionRecordKey.toString());

        StudentAnswerQuestionRecord studentAnswerQuestionRecord = userService.getByKeyForCassandra(answerQuestionRecordKey);

        String answerContent = studentAnswerQuestionRecord.getAnswerContent();
        String newAnswerContent = answerContent.replace("写入大量数据测试无实际意义","我被替换了");
        studentAnswerQuestionRecord.setAnswerContent(newAnswerContent);

        userService.updateForCassandra(studentAnswerQuestionRecord);


        return studentAnswerQuestionRecord.getpKey();
    }

}
